// WaterShader.java
package com.goldsprite.gameframeworks.shaders;

import com.badlogic.gdx.Gdx;

public class WaterShader extends BaseShader {
    // Uniform 位置
    private int uTimeLocation;
    private int uResolutionLocation;
    private int uWaveIntensityLocation;
    private int uWaveSpeedLocation;
    private int uRefractionStrengthLocation;
    private int uWaterColorLocation;

    // 参数
    private float waveIntensity = 0.02f;
    private float waveSpeed = 1.5f;
    private float refractionStrength = 0.01f;
    private float[] waterColor = new float[]{0.2f, 0.4f, 0.8f, 0.3f};

    public WaterShader() {
        super("shaders/water.vert", "shaders/water.frag");
    }

    @Override
    protected void initUniforms() {
        uTimeLocation = getUniformLocation("u_time");
        uResolutionLocation = getUniformLocation("u_resolution");
        uWaveIntensityLocation = getUniformLocation("u_waveIntensity");
        uWaveSpeedLocation = getUniformLocation("u_waveSpeed");
        uRefractionStrengthLocation = getUniformLocation("u_refractionStrength");
        uWaterColorLocation = getUniformLocation("u_waterColor");
    }

    @Override
    public void setUniforms() {
        setUniformf(uTimeLocation, getUTime());
        setUniformf(uResolutionLocation, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        setUniformf(uWaveIntensityLocation, waveIntensity);
        setUniformf(uWaveSpeedLocation, waveSpeed);
        setUniformf(uRefractionStrengthLocation, refractionStrength);
        setUniformf(uWaterColorLocation, waterColor[0], waterColor[1], waterColor[2], waterColor[3]);
    }

    public void setWaveParameters(float intensity, float speed, float refraction) {
        this.waveIntensity = intensity;
        this.waveSpeed = speed;
        this.refractionStrength = refraction;
    }

    public void setWaterColor(float r, float g, float b, float a) {
        waterColor[0] = r;
        waterColor[1] = g;
        waterColor[2] = b;
        waterColor[3] = a;
    }
}
